/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Courses {
    public static boolean insertCourse(Entity.Course cou)
    {
        try {
            String sql = "insert into tblCourses values (?,?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, cou.get_CoursesID());
            ps.setString(2, cou.get_CoursesName());
            ps.setString(3, cou.get_Description());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Courses.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateCourse(Entity.Course cou)
    {
        try {
            String sql = "update tblCourses set CoursesName = ?, Description = ? where CoursesID = ?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, cou.get_CoursesName());
            ps.setString(2, cou.get_Description());
            ps.setString(3, cou.get_CoursesID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Courses.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static void deleteCourse(String strCoursesID)
    {
        try {
            String sql = "delete from tblCourses where CoursesID = '" + strCoursesID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Courses.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
